<template>
<h1>表格组件</h1>

  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="date" label="Date" width="180" />
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="address" label="Address" />
  </el-table>

  <el-table :data="arr" style="width: 600px ;margin: 0 auto">
    <el-table-column type="index" width="80px" align="center" label="编号" />
    <el-table-column prop="name" label="姓名" align="center" />
    <el-table-column prop="salary" label="工资" align="center"/>
    <el-table-column prop="job" label="岗位" align="center"/>
<el-table-column>
<!--自定义列表模板  -->
  <template #default="scope">
<!--  scope对象保存了当前行的数据的索引$index(从0 开始）
  与当前行完整的对象scope.row-->
    <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
  </template>
</el-table-column>

  </el-table>



</template>

<script setup>
import {ref} from "vue";

const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
const arr = ref([
  {name:'花花',salary:2000,job:'保安'}
])

const del=(index,emp)=>{
  if(confirm('是否删除？'+emp.name)){
    arr.value.splice(index,1);
  }
}
</script>

<style scoped>

</style>